package com.hy.mybatisplus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.http.ResponseEntity;

import io.swagger.annotations.ApiOperation;
import com.hy.mybatisplus.request.PeopleEntityRequest;
import com.hy.mybatisplus.service.PeopleService;
import com.hy.mybatisplus.config.PageDto;
import com.hy.mybatisplus.config.SearchRequest;


/**
 * 描述:
 * author: hy
 * date: 2020-09-28
 */
@RestController
@RequestMapping(value = "/people")
@Api(value = "模块", description = "模块接口")
public class PeopleController {

    @Autowired
    private PeopleService peopleService;

    @RequestMapping(value = "/people/page", method = RequestMethod.GET)
    @ApiOperation(value = "列表接口")
    @ResponseBody
    public ResponseEntity<?> page(PageDto pageDto, PeopleEntityRequest request, SearchRequest saerchRequest) {
        return ResponseEntity.ok(peopleService.searchPage(request, pageDto, saerchRequest));
    }

    @RequestMapping(value = "/people", method = RequestMethod.POST)
    @ApiOperation(value = "保存接口")
    @ResponseBody
    public ResponseEntity<?> add(@RequestBody PeopleEntityRequest request) {
        return ResponseEntity.ok(peopleService.insert(request));
    }

    @RequestMapping(value = "/people", method = RequestMethod.PUT)
    @ApiOperation(value = "编辑接口")
    @ResponseBody
    public ResponseEntity<?> update(@RequestBody PeopleEntityRequest request) throws Exception {
        return ResponseEntity.ok(peopleService.updateById(request));
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除接口")
    public ResponseEntity<?> delete(@PathVariable String id) {
        return ResponseEntity.ok(peopleService.deleteById(id));
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过ID获取详情接口")
    public ResponseEntity<?> findbyid(@PathVariable String id) {
        return ResponseEntity.ok(peopleService.findById(id));
    }

}
